#include "Node.h"
#include <sfml/Graphics.hpp>
#include "Mesh.h"

Node::Node( int id, Node* parent ) : mScale(1.0f, 1.0f, 1.0f)
{
	mId = id;
	mParent = parent;
	mMesh = NULL;

	if (parent) {
		parent->mChildNodes.push_back(this);
	}
}

Node::~Node(void)
{

}

void Node::Display()
{
	if (!mMesh) {
		return;
	}

	glPushMatrix();

	glTranslatef(mPosition.x, mPosition.y, mPosition.z);
	glScalef(mScale.x, mScale.y, mScale.z);

	glPushName(mId);

	mMesh->Render();

	glPopName();

	NodeList::iterator it = mChildNodes.begin();

	while (it != mChildNodes.end())
	{
		Node *node = *it;
		node->Display();
		it++;
	}

	glPopMatrix();
}

void Node::SetPosition( const Vector3& position )
{
	mPosition = position;
}

void Node::SetMesh( Mesh* mesh )
{
	mMesh = mesh;
}

void Node::SetScale( const Vector3& scale )
{
	mScale = scale;
}
